package com.bj58.mis.apm.server.kylinreceive.repository;

import com.bj58.mis.apm.server.kylinreceive.model.KylinSegment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * kylin项目关联表操作jpa
 * @author wangxw
 */
public interface KylinSegmentRepository extends JpaRepository<KylinSegment, Long> {

    List<KylinSegment> queryByCubeIdAndIsDelete(String cubeId, Boolean isDelete);

    @Query(value = "SELECT sum(s.size) hbaseDataSize, sum(s.input_records_size) metaDataSize FROM kylin_segment s where s.is_delete = 0 and s.cube_id = :cubeId", nativeQuery = true)
    Map<String, Object> queryCubeTotalSize(@Param("cubeId") String cubeId);

    @Query(value = "SELECT s.cube_id cubeId, sum(s.size) hbaseDataSize, sum(s.input_records_size) metaDataSize FROM kylin_segment s " +
                   "left join kylin_cube c on s.cube_id = c.id and c.is_delete = 0 where s.is_delete = 0 and s.status = 'READY' group by s.cube_id", nativeQuery = true)
    List<Map<String, Object>> queryAllCubeTotalSize();
}
